package com.miukoo.aikao.qpaper.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miukoo.aikao.core.dtos.PageReqDto;
import com.miukoo.aikao.core.dtos.PageResDto;
import com.miukoo.aikao.qpaper.dto.PaperQuestionAnswerDto;
import com.miukoo.aikao.qpaper.dto.ext.PaperQuestionAnswerExtDto;
import com.miukoo.aikao.qpaper.mapper.PaperQuestionAnswerMapper;
import com.miukoo.aikao.qpaper.pojos.PaperQuestionAnswer;
import com.miukoo.aikao.qpaper.service.PaperQuestionAnswerService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* <p>
* 语言设置 服务实现类
* </p>
*
* @author 聪明笨狗
* @since 2020-05-25 16:33
*/
@Service
public class PaperQuestionAnswerServiceImpl extends ServiceImpl<PaperQuestionAnswerMapper, PaperQuestionAnswer> implements PaperQuestionAnswerService {

    @Override
    public PageResDto<List<PaperQuestionAnswer>> paging(PageReqDto<PaperQuestionAnswerDto> reqDto) {
        //创建分页对象
        IPage<PaperQuestionAnswer> query = new Page<>(reqDto.getCurrent(), reqDto.getSize());
        //查询条件
        QueryWrapper<PaperQuestionAnswer> wrapper = new QueryWrapper<>();
        //获得数据
        IPage<PaperQuestionAnswer> page = this.page(query, wrapper);
        return PageResDto.result(page.getTotal(),page.getRecords());
     }

    @Override
    public List<PaperQuestionAnswerExtDto> listForExam(Long paperId, Long questionId) {
        return baseMapper.list(paperId, questionId);
    }

    @Override
    public List<PaperQuestionAnswer> listForFill(Long paperId, Long quId) {
        //查询条件
        QueryWrapper<PaperQuestionAnswer> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(PaperQuestionAnswer::getPaperId, paperId)
                .eq(PaperQuestionAnswer::getQuestionId, quId);

        return this.list(wrapper);
    }
}
